package com.xiaoyu.lanling.feature.chat.viewholder.tease

import `in`.srain.cube.views.list.ViewHolderBase
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.emoji.widget.EmojiTextView
import com.xiaoyu.base.utils.extensions.getViewTag
import com.xiaoyu.base.utils.extensions.setOnClickDebounceListener
import com.xiaoyu.base.utils.extensions.setViewTag
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.event.chat.tease.TeaseClickEvent
import com.xiaoyu.lanling.feature.chat.model.tease.TeaseItem

class TeaseViewHolder : ViewHolderBase<TeaseItem>() {

    companion object {
        private val sOnItemClickListener = View.OnClickListener { v ->
            val itemData = v.getViewTag<TeaseItem>() ?: return@OnClickListener
            TeaseClickEvent(itemData.statement, itemData.id).post()
        }
    }

    private var mTitle: EmojiTextView? = null

    override fun createView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        val view = layoutInflater.inflate(R.layout.item_chat_tease, parent, false)
        mTitle = view.findViewById(R.id.title)
        view.setOnClickDebounceListener(sOnItemClickListener)
        return view
    }

    override fun showData(position: Int, itemData: TeaseItem) {
        mTitle?.text = itemData.statement
        mCurrentView?.setViewTag(itemData)
    }
}